package com.imay.live.utils;

import com.imay.live.cache.UserInfoCache;
import com.imay.live.model.NotifyMessageModel;
import com.imay.live.model.RecentContactInfo;
import com.imay.live.model.SendMessageModel;
import com.imay.live.model.TextMessageModel;

/**
 * Created by  nick on 2017/5/6 0006.
 * model 转换(适用于接口返回数据字段不统一)
 */

public class ModelCovertUtil {
    /**
     * 接收私信的通知内容-->私信列表的model
     * @param model
     * @return
     */
    public static RecentContactInfo convertNotifyMessageModel(NotifyMessageModel model){
        RecentContactInfo info = new RecentContactInfo();
        info.setLatestMsg(model.getContent());
        info.setLatestMsgTime(model.getTimeStamp());
        info.setUnReadRecordCount(1);
        info.setUserChannelId(model.getUserChannelId());
        info.setYourImgHead(model.getImgHead());
        info.setYourUid(model.getUid());
        info.setYourNick(model.getNick());
        info.setYourUserLv(model.getUserLv());
        info.setYourVip(model.getVip());
        return info;
    }

    /**
     * 发送私信成功返回的数据-->私信记录的model
     * @param model
     * @return
     */
    public static TextMessageModel.RecordModel convertMessageRecordModel(SendMessageModel model,String content){
        TextMessageModel.RecordModel info = new TextMessageModel.RecordModel();
        info.setContent(content);
        info.setCreateAt(model.getTimeStamp());
        info.setUid(UserInfoCache.getUserInfo().getUser().getUid());
        info.setFirstChat(0);
        info.setHeadImg(UserInfoCache.getUserInfo().getUser().getImgHead());
        info.setChatRecordId(model.getChatRecordId());
        return info;
    }

    /**
     * 私信记录的model->发送私信成功返回的数据
     * @return
     */
    public static SendMessageModel convertSendMessageModel(TextMessageModel.RecordModel info){
        SendMessageModel model = new SendMessageModel();
        model.setContentLocal(info.getContent());
        model.setTimeStamp(info.getCreateAt());
        return model;
    }


    /**
     * 发送私信成功返回的数据-->私信记录的model
     * @param model
     * @return
     */
    public static TextMessageModel.RecordModel convertNotifyMessageModelToRecordModel(NotifyMessageModel model){
        TextMessageModel.RecordModel info = new TextMessageModel.RecordModel();
        info.setChatRecordId(model.getChatRecordId());
        info.setContent(model.getContent());
        info.setUid(model.getUid());
        info.setHeadImg(model.getImgHead());
        info.setCreateAt(model.getTimeStamp());
        return info;
    }


}
